<?php
	header("Content-type: text/html;charset=utf8");
	require_once("../db/dbclass.php");
	$myDb=&DbController::getInstance();
	$userid=$_POST['user_id'];
	$friendid=$_POST['friend_id'];
	$primsgid=$_POST['primsg_id'];
	$type=$_POST['time'];
	switch ($type) {
		case '0':
		//历史消息的前20条
			$param="SELECT * FROM yj_primsg WHERE primsg_id < $primsgid AND sender_id IN ($userid,$friendid) LIMIT 20" ;
			break;
		
		default:
		//最新消息全部
			$param="SELECT * FROM yj_primsg WHERE primsg_id > $primsgid AND sender_id IN ($userid,$friendid)" ;
			break;
	}
	$arr_messege="";
	$result=$myDb->exec_query($param);
	if($result==TRUE){
		$result_row= mysqli_num_rows($result);
		$num=$result_row;
		$arr_messege=array($num);
		$i=0;
		while($row=mysqli_fetch_array($result,MYSQL_ASSOC)){
			$array_i=array(
					"prismg_id"=>$row['primsg_id'],
					"sender_id"=>$row['sender_id'],
					"receiver_id"=>$row['receiver_id'],
					"content"=>$row['primsg_content'],
					"receive_date"=>$row['primsg_time']
					);
			$arr_messege[$i++]=$array_i;
		}
		$arr=array(
			"result"=>"success",
			"message"=>$arr_messege
		);
		echo json_encode($arr);
		return;
	}
	$arr=array(
		"result"=>"failure",
		"message"=>$arr_messege
	);
	echo json_encode($arr);
?>